package com.yyb.learn.jbusine.controller;

import com.alibaba.fastjson.JSONObject;
import com.yyb.common.bo.LoginUser;
import com.yyb.common.bo.RegisterUser;
import com.yyb.learn.jbusine.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author yuyb40219
 * @Date 2021/9/28 15:03
 * Description:
 */
@RestController
@RequestMapping("/user")
public class UserController {

    private static Logger LOG = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    /**
     * 注册
     * @param registerUser
     * @return
     */
    @RequestMapping(value = "/register.json", method = RequestMethod.POST)
    public JSONObject register(@RequestParam RegisterUser registerUser) {
        LOG.info("[{}] Enter register by phone ", registerUser.getPhone());
        return userService.register(registerUser);
    }

    /**
     * 登录
     * @param loginUser
     * @return
     */
    @RequestMapping(value = "/login.json", method = RequestMethod.POST)
    public JSONObject login(@RequestParam LoginUser loginUser) {
        LOG.info("[{}] Enter login by phone ", loginUser.getPhone());
        return userService.login(loginUser);
    }

}